#pragma once
#include "Defines.h"

enum user_message_types
{
	ID_GAME_STATE = ID_USER_PACKET_ENUM +1,
	ID_NEW_GAME,
};

struct msg
{
	//Numbers that will be filled in by the server
	//What year it is
	int year;
	//How many people have starved this year
	int starved;
	//Was there a plague
	int plague;
	//What is the current population
	int pop;
	//How many new people have arrived
	int newbs;
	//How many acres does the kingdom own
	int acres;
	//How many acrea were farmed
	int farmed;
	//How many bushels were ate by rats
	int rats;
	//How mnay buchels do you have
	int bushels;
	//How many buchels is land worth (per acre)
	///Min 17, Max 26
	int bpa;
	//Which client are you, this is determined by the server when the player connectes
	int client;

	//Numbers that will be filled in by the client
	//How much land will you buy (negitive to sell land)
	int buysell;
	//How much food will you feed your citizens (each needs 20 per)
	int feed;
	//How many acres will you plant
	int plant;

	bool isEmpty()
	{
		if((year!=CLEAN_NUMBER)&&
			(starved!=CLEAN_NUMBER)&&
			(plague!=CLEAN_NUMBER)&&
			(pop!=CLEAN_NUMBER)&&
			(newbs!=CLEAN_NUMBER)&&
			(acres!=CLEAN_NUMBER)&&
			(farmed!=CLEAN_NUMBER)&&
			(rats!=CLEAN_NUMBER)&&
			(bushels!=CLEAN_NUMBER)&&
			(bpa!=CLEAN_NUMBER)&&
			(buysell!=CLEAN_NUMBER)&&
			(feed!=CLEAN_NUMBER)&&
			(plant!=CLEAN_NUMBER))
			return false;
		return true;
	}

	void setVoid()
	{
		year	  = CLEAN_NUMBER;
		starved = CLEAN_NUMBER;
		plague  = CLEAN_NUMBER;
		pop     = CLEAN_NUMBER;
		newbs   = CLEAN_NUMBER;
		acres   = CLEAN_NUMBER;
		farmed  = CLEAN_NUMBER;
		rats    = CLEAN_NUMBER;
		bushels = CLEAN_NUMBER;
		bpa     = CLEAN_NUMBER;
		buysell = CLEAN_NUMBER;
		feed    = CLEAN_NUMBER;
		plant   = CLEAN_NUMBER;
	}
	void copy(msg& message)
	{
		year = message.year;
		starved = message.starved;
		plague = message.plague;
		pop = message.pop;
		newbs = message.newbs;
		acres = message.acres;
		farmed = message.farmed;
		rats = message.rats;
		bushels = message.bushels;
		bpa = message.bpa;
		buysell = message.buysell;
		feed = message.feed;
		plant = message.plant;
	}

	void convert(char* data)
	{
		int counter = 0;
		char c = 1;
		char temp[50];
		ZeroMemory(temp,50);
		for (int i = 1; i < strlen(data); i++)
		{
			if(data[i]=='.')
			{
				switch (counter)
				{
				case 0:
					acres = atoi(temp);
					break;
				case 1:
					bpa = atoi(temp);
					break;
				case 2:
					bushels = atoi(temp);
					break;
				case 3:
					buysell = atoi(temp);
					break;
				case 4:
					client = atoi(temp);
					break;
				case 5:
					farmed = atoi(temp);
					break;
				case 6:
					feed = atoi(temp);
					break;
				case 7:
					newbs = atoi(temp);
					break;
				case 8:
					plague = atoi(temp);
					break;
				case 9:
					plant = atoi(temp);
					break;
				case 10:
					pop = atoi(temp);
					break;
				case 11:
					rats = atoi(temp);
					break;
				case 12:
					starved = atoi(temp);
					break;
				case 13:
					year = atoi(temp);
					break;
				default:
					break;
				}
				ZeroMemory(temp,50);
				counter++;
			}
			else
				sprintf_s(temp,"%s%c",temp,data[i]);
		}
	}

	void convertTo(char* out)
	{
		sprintf_s(out,MESSAGE_BUFF,"%c%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.\0",(unsigned char)ID_GAME_STATE,
			acres,bpa,bushels,buysell,client,farmed,feed,
			newbs,plague,plant,pop,rats,starved,year);
	}
};